package network.exercise.exercise1;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-04-05
 * Time:17:35
 */
public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9999);
        Socket socket = serverSocket.accept();
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String data;
        while ((data = br.readLine()) != null) {
            reply(socket,data);
        }
        socket.close();
    }
    public static void reply(Socket socket,String data) throws IOException {
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        if (data.equals("name")) {
            bw.write("I'm Bob");
        } else if (data.equals("hobby")) {
            bw.write("Programing Java program");
        } else {
            bw.write("I don't understand");
        }
        bw.newLine();
        bw.flush();
    }
}
